home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / prog / dtbl11.zip / DEMO4.FRM (.txt) < prev    next >
Visual Basic Form  |  1993-05-11  |  13KB  |  238 lines

  1. Form1
  2. !DataTable Example Program - DEMO4
  3. Form1
  4. Customer
  5.     DATATABLE
  6. C:\CUSTOMER
  7. Label1
  8. Name:
  9. CustomerName
  10. Label2
  11. Address:
  12. Address
  13. Label3
  14. City:
  15. Label4
  16. State:
  17. State
  18. Label5
  19. Label6
  20. Phone:
  21. Phone
  22.     TopButton
  23. NextButton
  24. InsertButton
  25. Insert
  26. DeleteButton
  27. Delete
  28. QuitButton
  29. BottomButton
  30. Bottom
  31. PreviousButton
  32. Previous
  33. UpdateButton
  34. Update
  35. ClearButton
  36. Clear
  37. QuitButton_Click
  38. Form_Click
  39.     Form_Load>
  40. Customer
  41.     OpenTableg
  42. Action
  43. CloseTable%
  44. FillForm
  45.     GetRecord
  46.     FieldName
  47. GetField
  48. CustomerName:
  49. Text$
  50. FieldValue
  51. Address
  52. StateW
  53. Phone}
  54.     InsertRecW
  55. PutField
  56. InsertRecord
  57. InsertButton_Click
  58. ClearButton_Click
  59. TopButton_Click
  60. FirstRecord
  61. BottomButton_Click
  62. LastRecord
  63. NextButton_ClickA
  64. NextRecord
  65. PreviousButton_ClickJ
  66. PreviousRecord
  67. DeleteButton_Click
  68. DeleteRecord4
  69.     UpdateRec
  70. UpdateRecord
  71. UpdateButton_Click
  72. Reaction
  73. DisplayError
  74. TheError
  75. CustomerName_Change
  76. CustomerName_LostFocus
  77. SearchMode
  78. SEARCHFIRST
  79. SearchField
  80. TheNameTyped'
  81. database
  82. tableN
  83.     DataTable
  84.     KeySearch
  85.     SearchKey
  86. FillCustomerCombo
  87. EmptyCustomerCombo
  88.     ListCount
  89. Form_Load
  90. Open up the database table
  91. Fill the combo box with customer names
  92. Now fill the form with data 
  93. in the first record.
  94. QuitButton_Click
  95. Close the database table
  96. And quit the program
  97. FillForm
  98. We need to get the current record in the database:
  99. Ok, now lets get the values in the database fields for the
  100. record we just read in::
  101. We need to make a one-to-one relationship between the fields in the database table
  102. and the fields on our Visual Basic Form. We will read in the field values from the
  103. database record and place those values into the .TEXT property of our TEXT controlss
  104. on our Visual Basic form. For each field of interest this is a three-step process:
  105. 1. Specify the name of the database field of interest ---> DataTable.FieldName = "
  106. 2. Get the field value ---> DataTable.Action = GetFieldd
  107. 3. Place the field value in the TEXT control ---> Text1.TEXT = DataTable.FieldValuee
  108. Thats all there is to it!!
  109. You should make a FillForm like subroutine position independent. Notice that the first line of
  110. code in this subroutine reads in the current record. Use other routines to move around
  111. in the table (like the TOP,BOTTOM, NEXT and PREVIOUS buttons in this demo). Making the
  112. routine position independent means that it can be used and re-used at any time to fill inn
  113. your form with information from any record in your database.
  114. We will fill in the form now:o
  115. Address"
  116. State"
  117. Phone"
  118. InsertRec
  119. Here we transfer the information from the Visual Basic Form and insert itt
  120. into the database table.
  121. To do this requires a three-step process for each field in the database table:
  122. 1. Specify the name of the field of interest ---> DataTable.FieldNamee
  123. 2. Specify the field value ---> DataTable.FieldValue = A String valuee
  124. 3. Put the field into the DataTable record ---> DataTable.Action = PutFieldd
  125. We do this for each field in the database table.
  126. When we are finished we INSERT the record into the
  127. database table ---> DataTable.Action = InsertRecordd
  128. Address"
  129. State"
  130. Phone"
  131. InsertButton_Click
  132. ClearButton_Click
  133. This code simply clears the text in all of the Visual Basic form's Text controls..
  134. TopButton_Click
  135. The following code moves to the first record in the data basen
  136. and fills in our form with the information found in that first
  137. record
  138. Moveto the first record in the database
  139. Fill in the form with data
  140. BottomButton_Click
  141. The following code moves to the last record in the data base
  142. and fills in our form with the information found in that last
  143. record
  144. Move to the last recordd
  145. Fill the form 
  146. NextButton_Click
  147. The following code moves to the next record in the database table. If an
  148. error is encountered during the move to the next record an error message is displayed.
  149. The DisplayError subroutine is an example of the structure of a generalized 
  150. DataTable error handling routine. 
  151. Once the repositioning to the next record is successfull, we fill in our form
  152. with information from that record.
  153. Moving to the next record in the databaseu
  154. If an errort
  155. Display the DataTable errore
  156. If no error
  157. Fill in our form with the information in the record.
  158. PreviousButton_Click
  159. The following code moves to the previous record in the database table. If an
  160. error is encountered during the move to the record an error message is displayed.a
  161. The DisplayError subroutine is an example of the structure of a generalizedl
  162. DataTable error handling routine. 
  163. Once the repositioning to the previous record is successfull, we fill in our forma
  164. with information from that record.
  165. Moving to previous records
  166. If an errors
  167. Display the DataTable Errorr
  168. If no error
  169. Fill in our form with info from the record
  170. DeleteButton_Click
  171. This code deletes the current record from the database
  172. The current record after the delete is performed, is the record immediatelyr
  173. following the deleted record. We then fill in our form with info from that
  174. record.n
  175. We will delete the current record.
  176. Now fill in form with the current record.
  177. UpdateRec
  178. Here we transfer the information from the Visual Basic Form and update the current record
  179. in the database table.
  180. To do this requires a three-step process for each field in the database table:
  181. 1. Specify the name of the field of interest ---> DataTable.FieldNames
  182. 2. Specify the field value ---> DataTable.FieldValue = A String values
  183. 3. Put the field into the DataTable record ---> DataTable.Action = PutFieldl
  184. We do this for each field in the database table.
  185. When we are finished we UPDATE the record in the
  186. database table ---> DataTable.Action = UpdateRecordd
  187. Address"
  188. State"
  189. Phone"
  190. UpdateButton_Click
  191. DisplayError
  192. Here we show how to build a general purpose error routine for the DataTablee
  193. it is not complete but gives you the basic idea of how to build such a routine..
  194. For a listting of all DataTable error codes see the Working Model documentation.
  195. Drive not ready!
  196. Directory not found!
  197. File is busy!"
  198. File is Locked!"
  199. File not Found!"
  200.  Record not Found!
  201. End of Table!"
  202. Start of Table!"
  203. Unknown Error!
  204. CustomerName_LostFocus
  205. This code demonstrates how to search a database on a specific key.
  206. When you leave this field, this lost focus subroutine is executed.
  207. The value in the CustomerName.Text is then searched for in the database table.
  208. The database field searched is "Name" (The only key field in this example).l
  209. If the search is successfull the record is displayed on the form. If the search
  210. fails an error message is displayed, the form is cleared (with the typed in value)
  211. replaced in the CustomerName.Text expecting to get a new customer's information.
  212. Temporary variable to hold Customer's name.c
  213. The first and only field in PRIMARY index 
  214. The first and only field of the keye
  215. The value to search forf
  216. Submit the search criteria
  217. Perform the search
  218. If an errorh
  219. Display the errort
  220. Assume new customer, temp store for new customer name'
  221. Clear the form
  222. Place the new customer name back in the form
  223. Now let the user type in the new infoa
  224. Search was successfull
  225. Fill in the form with customer infoa
  226. FillCustomerCombo
  227. Move to first record in the CUSTOMER database 
  228. We want to put customer names in the combo box
  229. Loop to fill combo box with customer names
  230. Get the record
  231. Get the customer named
  232. Add name to the list
  233. Move to next recorde
  234. Reposition to the first record
  235. EmptyCustomerCombo
  236. Here we empty the combo box to eliminate duplicate names
  237. Loop to remove names from list
  238.